<?php


namespace app\api\controller;


use app\api\logic\UserAddressLogic;
use app\api\validate\UserAddressValidate;

class UserAddressController extends BaseShopController
{
    /**
     * @notes 地址列表
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     * @author ljj
     * @date 2022/2/24 10:45 上午
     */
    public function lists()
    {
        $result = (new UserAddressLogic())->lists($this->userId);
        return $this->success('',$result);
    }

    /**
     * @notes 添加地址
     * @return \think\response\Json
     * @author ljj
     * @date 2022/2/24 10:52 上午
     */
    public function add()
    {
        $params = (new UserAddressValidate())->post()->goCheck('add');
        $params['user_id'] = $this->userId;
        (new UserAddressLogic())->add($params);
        return $this->success('操作成功',[],1,1);
    }

    /**
     * @notes 地址详情
     * @return \think\response\Json
     * @author ljj
     * @date 2022/2/24 11:56 上午
     */
    public function detail()
    {
        $id = $this->request->get('id');
        $result = (new UserAddressLogic())->detail($id);
        return $this->success('',$result);
    }

    /**
     * @notes 编辑地址
     * @return \think\response\Json
     * @author ljj
     * @date 2022/2/24 11:59 上午
     */
    public function edit()
    {
        $params = (new UserAddressValidate())->post()->goCheck('edit');
        $params['user_id'] = $this->userId;
        (new UserAddressLogic())->edit($params);
        return $this->success('操作成功',[],1,1);
    }

    /**
     * @notes 设置默认地址
     * @return \think\response\Json
     * @author ljj
     * @date 2022/2/24 12:08 下午
     */
    public function setDefault()
    {
        $params['id'] = $this->request->post('id');
        $params['user_id'] = $this->userId;
        (new UserAddressLogic())->setDefault($params);
        return $this->success('操作成功',[],1,1);
    }

    /**
     * @notes 删除地址
     * @return \think\response\Json
     * @author ljj
     * @date 2022/2/24 2:35 下午
     */
    public function del()
    {
        $id = $this->request->post('id');
        (new UserAddressLogic())->del($id);
        return $this->success('操作成功',[],1,1);
    }
}